package com.controller.test;

import com.bean.entity.AnswerInfo;
import com.bean.pojo.Dto;
import com.bean.pojo.PageAssistant;
import com.bean.util.DtoUtil;
import com.bean.vo.AnswerInfoVo;
import com.service.AnswerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("answer")
public class StudentAnswerController {

    @Autowired
    private AnswerInfoService answerInfoService;

    @RequestMapping("query")
    public Dto queryAllTestDetail(Integer page, Integer limit, PageAssistant<AnswerInfoVo> pa){
        System.out.println(">>>试题管理>>>学生作答详情");

        pa.setCurrPage(page);
        pa.setPageSize(limit);

        Map<String ,Object> map= new HashMap<String,Object>();
        PageAssistant<AnswerInfoVo> answerInfo = answerInfoService.queryByPage(map, pa);

        return DtoUtil.returnSuccess(answerInfo);
    }

    @RequestMapping("add")
    public Dto addAnswer(AnswerInfo answerInfo){
        System.out.println(">>>增加作答信息");
        System.out.println(answerInfo);

        try {
            answerInfoService.save(answerInfo);
            return DtoUtil.returnSuccess();

        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail(e.getMessage());
        }
    }

    @RequestMapping("modify")
    public Dto modifyAnswer(AnswerInfo answerInfo){
        System.out.println(">>>修改作答信息");
        System.out.println(answerInfo);

        try {
            answerInfoService.modify(answerInfo);
            return DtoUtil.returnSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail(e.getMessage());
        }
    }

    @RequestMapping("delete")
    public Dto teacherDeleteStu(AnswerInfo answerInfo){
        System.out.println(">>>删除作答信息");
        System.out.println(answerInfo);

        try {
            answerInfoService.remove(answerInfo);
            return DtoUtil.returnSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail(e.getMessage());
        }
    }
}
